
package com.hoopchina;

import com.hoopchina.news.R;
import com.hoopchina.data.AppInfo;
import com.hoopchina.ui.details.DetailsView;
import com.hoopchina.ui.details.MyFavoritesView;
import com.hoopchina.ui.download.DownloadActivity;
import com.hoopchina.ui.home.F1;
import com.hoopchina.ui.home.GoalHi;
import com.hoopchina.ui.home.HomeView;
import com.hoopchina.ui.main.BaseActivity;
import com.hoopchina.ui.main.ILocalNewsChanged;
import com.hoopchina.ui.main.ResizeLayout;
import com.hoopchina.ui.main.Splash;
import com.hoopchina.ui.main.TabBar;
import com.hoopchina.ui.main.TabBarButtonId;
import com.hoopchina.ui.main.TitleBar;
import com.hoopchina.ui.main.UIWidget;
import com.hoopchina.ui.main.ViewManager;
import com.hoopchina.ui.search.SearchView;
import com.hoopchina.util.DialogUtils;
import com.hoopchina.util.LogUtils;
import com.hoopchina.util.ResourceUtils;
import com.hoopchina.util.download.DownloadMgr;
import com.hoopchina.weibo.ui.ForwardingView;
import com.hoopchina.weibo.ui.WeiboAuthActivity;
import android.app.Activity;
import android.app.ActivityGroup;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends ActivityGroup  {
	private LinearLayout     mContainer;                     // the view container
    private ViewManager      mViewManager;                   // view manager
    private TabBar           mTabBar;                        // tab bar widget
    public static TitleBar         mTitleBar;                      // title bar widget
    private Splash           mSplash;                        // splash widget
    private ImageButton      mUserGuide;
    private EventObserver    mEventObserver;                 // control event observer
    private ProgressDialog   mProgressDiaLogUtils;
    private boolean          mIsProgressDiaLogUtilsShownOnPaused;
    private String           mSavedProgressDiaLogUtilsMessage;
    private boolean          _isFullScreenEnabled;
	private TextView mTxtView;
    private boolean mAlreadyStarted ;
	private ResizeLayout mMainView;
	private final int VIEW_RESIZE_LIMIT = 70;
	private final int MSG_RESIZE = 3;
    protected static final int MSG_SHOW_TABBAR = 4;
    protected static final int MSG_HIDE_TABBAR = 5;
	protected static final int RESIZE_ZOOM_OUT = 0;
	protected static final int RESIZE_ZOOM_IN = 1;
	private int type = 3;
	private NotificationClickedReceiver mReceiver = null;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        LogUtils.d("in");
        super.onCreate(savedInstanceState);
//		setTheme( android.R.style.Theme_Light_NoTitleBar_Fullscreen );
        setContentView(R.layout.main);	
        
        getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        mAlreadyStarted=true;
        initFields();
        
        ResourceUtils.setContext( this );
        DialogUtils.setContext( this );
        
        mTabBar.setFocusedButton( TabBarButtonId.EHOME );
        mViewManager.showView( HomeView.Id, HomeView.class, false, null, true );
        
        registerReceiver();
     mSplash.startClosing();
//        updateWidget(getIntent());
        
        mTabBar.setDecorIcon( TabBarButtonId.FINANCIAL, R.drawable.tabbar_decor, "99+" );
        LogUtils.d("out");
    }
    
    // From Activity
    public void onResume() {
        LogUtils.d("in");
        super.onResume();
        AppInfo.init(this);
        
        if ( mIsProgressDiaLogUtilsShownOnPaused ) {
        	showWaitingDialog( mSavedProgressDiaLogUtilsMessage );
        }
    //    updateWidget(getIntent());
        mViewManager.setTabBarVisibility( true );   
        LogUtils.d("out");
    }
    
    /**
     * widget change view to searchview and details view
     * @param intent
     */
    public void updateWidget(Intent intent){
    	Bundle widgetBundle = intent.getExtras();
    	Log.d("Download","MainActivity updateWidget() in ");
    	if(widgetBundle!=null){
    		LogUtils.d("intent.getStringExtra(widgetflag)!=null ");
    		mSplash.setVisibility(View.GONE);
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
            getWindow().clearFlags(
                    WindowManager.LayoutParams.FLAG_FULLSCREEN); 
            String widgetflag = widgetBundle.getString("widgetflag");
    		if(widgetflag.equals("search41")){
    			doChangeView(TabBarButtonId.ESEARCH);
    			mTitleBar.showLoadingProgressBar(false);
    			return ;
    		}else if (widgetflag.equals("largewidget")){
    			Bundle aBundle = new Bundle();
    			aBundle.putInt("NewPosition", intent.getIntExtra("NewPosition", 1));
    			System.out.println("-----------position="+intent.getIntExtra("NewPosition", 1));
    			aBundle.putInt("Type", 3);
    			mViewManager.setTabBarVisibility(false);
    			mViewManager.showAssistButton(false);
    			mViewManager.showLoadingProgressBar(false);
    	        mViewManager.showClearOnTopView( DetailsView.Id, DetailsView.class, true, aBundle);
    			return ;
        	}else if (widgetflag.equals("widget41")){
    			Bundle aBundle = new Bundle();
    			aBundle.putInt("NewPosition", intent.getIntExtra("NewPosition", 1));
    			aBundle.putInt("Type", 4);
    	        mViewManager.showClearOnTopView( DetailsView.Id, DetailsView.class, true, aBundle);
    			mViewManager.setTabBarVisibility(false);
    			mViewManager.showRefreshButton(false);
    			mTitleBar.displayWeatherBox(false);
    			mTitleBar.showLoadingProgressBar(false);
    			return ;
        	}
    		else if(widgetflag.equals("hotwordsearch")){
    			String hotword = intent.getStringExtra("hotword");
    			Bundle aBundle = new Bundle();
    			aBundle.putString("hotword", hotword);
    			mViewManager.showViewAndChangeTab(SearchView.Id, SearchView.class, aBundle, TabBarButtonId.ESEARCH);
    			mTitleBar.showLoadingProgressBar(false);
    			return ;
    		}
    		else
    		{
    			Message msg = new Message();
    	        if(isResizeViewShowTabBar()){
    	        	msg.what = MSG_SHOW_TABBAR;
    	        }
    	        else {
    	        	msg.what = MSG_HIDE_TABBAR;
    	        }
    	        mHandler.sendMessage(msg);
    		}
    	}
    	else if (mAlreadyStarted){
    		LogUtils.d("else if (mAlreadyStarted) ");
    		mSplash.startClosing();
		}
    	LogUtils.d("out");
    }
    
    // From Activity
    public void onDestroy() {
        LogUtils.d("in");
        mViewManager.finish();
        unregisterReceiver();
        
        super.onDestroy();
        LogUtils.d("out");
    }

    // From Activity
    public void onPause() {
        LogUtils.d("in");
    	if ( mProgressDiaLogUtils != null ) {
    		dismissWaitingDialog();
    		mIsProgressDiaLogUtilsShownOnPaused = true;
    	}
    	 mAlreadyStarted=false;
    	 
        super.onPause();
        LogUtils.d("out");
    }
    
    /**
     * Process the key down event on main activity
     */
    @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
        LogUtils.d("in");
        Activity currentAct = mViewManager.getCurrentActivity();
        // only care about back key
        if ( keyCode == KeyEvent.KEYCODE_BACK ) {
            if ( currentAct != null && !currentAct.onKeyDown( keyCode, event ) ) {
            	DialogUtils.showExitDialog(this);
            }
            return true;
        }
        else {
            return super.onKeyDown( keyCode, event );
        }
    }
    
    /**
     * A utility function for view manager 
     *   because it's not easy to pass all activity/view classes to view manager
     * @param aId the activity Id
     * @param aClass the activity class
     * @param aIsOnTopView if activity is clear_top view or new_task view
     * @param aBundle the data bundle
     * @return expected view instance
     */
    public View getViewByProperties( String aId, Class<?> aClass, boolean aIsOnTopView, Bundle aBundle ) {
        int flag = aIsOnTopView ? Intent.FLAG_ACTIVITY_CLEAR_TOP : Intent.FLAG_ACTIVITY_NEW_TASK;
        Intent intent = new Intent( MainActivity.this, aClass );
        intent.addFlags( flag );
        if ( aBundle != null ) {
            intent.putExtras( aBundle );
        }
        return getLocalActivityManager().startActivity( aId, intent ).getDecorView();
    }
    
    /**
     * Notified by event observer that tab bar button has been clicked
     * @param aButtonIndex tab bar button index
     */
    public void onTabbarButtonClicked( final int aButtonIndex ) {
        // Some time we must give prompt and a chance for user not to switch to other view
        //   unless they agree to. E.g. at the ordering stage, user should be notified he/she will be
        //   do all steps again if he/she move to other view now
    	boolean someCondition = false;
        if ( someCondition ) {
            // If we are in order activity, we have to give chance for user to not to switch to other tab
            //   because order activity will not be resumed once user returns to main tab
            DialogUtils.getQueryDialog(this, "change to another tab?", 
                new android.content.DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface diaLogUtils, int which) {
                        doChangeView( aButtonIndex );
                    }
                }, 
                new android.content.DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface diaLogUtils, int which) {
                        // no implementation
                    }
                }).show();
        }
        else {
            // everything is OK, now go to next view
            doChangeView( aButtonIndex );
        }
    }
    
    /**
     * Change to the expected view
     * @param aButtonIndex tab bar button index
     */
    private void doChangeView( int aButtonIndex ) {
        int currentFocusedButtonIndex = mTabBar.getFocusedButtonIndex();
        if ( currentFocusedButtonIndex == aButtonIndex ) {
            return;
        }
        if ( !mViewManager.onTabBarFocusedButtonChanged( aButtonIndex ) ) {
        	// when a first-level activity is launched at the first time
	        switch ( aButtonIndex ) {
	            case TabBarButtonId.EHOME:
	            	mViewManager.showView( HomeView.Id, HomeView.class, false, null, true );
	                break;
	            case TabBarButtonId.EFOCUS:
	            	mViewManager.showView( GoalHi.Id, GoalHi.class, false, null, true );
	                break;
	            case TabBarButtonId.EHOTLIST:
	            	mViewManager.showView( F1.Id, F1.class, false, null, true );
	                break;
	            case TabBarButtonId.FINANCIAL:
	            	mViewManager.showView( MyFavoritesView.Id, MyFavoritesView.class, false, null, true );
	                break;
	            case TabBarButtonId.ESEARCH:
	            	//mViewManager.showView( SettingsActivity.Id, SettingsActivity.class, false, null, true );
	                break;
	            default:
	                break;
	        }
        	// view manager handled view switch
            setFocusedButton( aButtonIndex );
        }
        // when another 1-level view is shown, we have to clear the view history
        //   to avoid disorder during back key pressing on other views
        // but this is somewhat annoying because all sub-views must be clear_top type
        //   otherwise it doesn't know to where it'll be back.
        //mViewManager.clearViewHistory();
    }
    
    /**
     * Get index of current focused tab bar button
     * @return
     */
    public int getFocusedTabBarButtonIndex() {
    	return mTabBar.getFocusedButtonIndex();
    }
    
    /**
     * Set the focused tab bar button
     * @param aButtonIndex
     */
    public void setFocusedButton( int aButtonIndex ) {
        mTabBar.setFocusedButton( aButtonIndex );
    }
    
    /**
     * Set tab bar visibility
     * @param aVisible
     */
    public void setTabBarVisibility( boolean aVisible ) {
    	mTabBar.setVisibility( aVisible ? View.VISIBLE : View.GONE );
    }
    
    public void setTitleBarVisibility( boolean aVisible ){
    	mTitleBar.setVisibility( aVisible ? View.VISIBLE : View.GONE );
    }
    
    /**
     * Notified by event observer that splash screen has been closed
     *   because splash has animation
     */
    public void onSplashClosed() {
        mSplash.setVisibility( View.GONE );
        getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
            getWindow().clearFlags(
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    
    /**
     * Set title bar text
     * @param aTitle title string
     */
    public void setTitle( String aTitle ) {
        mTitleBar.setTitle( aTitle );
    }
    
    public void setTitle( int aTitle ) {
        mTitleBar.setTitle( aTitle );
    }
    /**
     * Set title bar status
     * @param aStatus status text
     */
    public void setStatus( String aStatus ) {
        mTitleBar.setStatus( aStatus );
    }
    
    /**
     * Set title bar primary button
     * @param aListener
     */
    public void setPrimaryButton( OnClickListener aListener ) {
    	mTitleBar.setPrimaryButton( aListener );
    }
    
    /**
     * Set title bar back button
     * @param aListener the button click listener
     */
    public void setBackButton( String aText, OnClickListener aListener ) {
        mTitleBar.setBackButton( aText, aListener );
    }
    
    /**
     * 
     */
    public void hideLeftButton() {
    	mTitleBar.hideLeftButton();
    }
    public void showDetailViewBar(boolean isDisp) {
    	mTitleBar.showDetailViewBar(isDisp);
    }
      /**
     * 
     */
    public void displayWeatherBox(boolean isDisp) {
    	mTitleBar.displayWeatherBox(isDisp);
    }
     
    /**
     * Set title bar assist button
     * @param aText the button text
     * @param aListener the button click listener
     */
    public void setAssistButton( String aText, int aBgResource, OnClickListener aListener ) {
        mTitleBar.setAssistButton( aText, aBgResource, aListener );
    }
    
	public void setNextButton( OnClickListener aListener ) {
		mTitleBar.setNextButton( aListener );
	}
	
	public void setPreButton( OnClickListener aListener ) {
		mTitleBar.setPreButton( aListener );
	}
    
    public void showWaitingDialog( String aMessage ) {
    	if ( mProgressDiaLogUtils == null ) {
    		mProgressDiaLogUtils = ProgressDialog.show( this, getString( R.string.app_name ), aMessage );
    		mSavedProgressDiaLogUtilsMessage = aMessage;
    	}
    }
    
    public void dismissWaitingDialog() {
    	if ( mProgressDiaLogUtils != null ) {
    		mProgressDiaLogUtils.dismiss();
    		mProgressDiaLogUtils = null;
    	}
    }
    
    public void toggleFullScreen() {
    	_isFullScreenEnabled = !_isFullScreenEnabled;
    	doAnimOnTitleBar( !_isFullScreenEnabled );
    	//doAnimOnTabBar( !_isFullScreenEnabled );
    }
    
    
    public void doAnimOnTitleBar( boolean aEnabled ) {
    	AnimationSet titleBarAnimSet = null;
    	if ( aEnabled ) {
    		mTitleBar.setVisibility( View.VISIBLE );
	    	titleBarAnimSet = createAnim( 
	    			0, 0, -mTitleBar.getHeight(), 5,
	    			0, 1, null, true );
    	}
    	else {
    		titleBarAnimSet = createAnim( 
    			0, 0, 5, -mTitleBar.getHeight(),
    			1, 0, mTitleBar, false );
    	}
		mTitleBar.startAnimation( titleBarAnimSet );
    }
    
    @SuppressWarnings ( "unused" )
    private void doAnimOnTabBar( boolean aEnabled ) {
    	AnimationSet tabBarAnimSet = null;
    	if ( aEnabled ) {
			mTabBar.setVisibility( View.VISIBLE );
    		tabBarAnimSet = createAnim( 
    				0, 0, mTabBar.getHeight(), -5,
	    			0, 1, null, true );
    	}
    	else {
    		tabBarAnimSet = createAnim( 
    				0, 0, -5, mTabBar.getHeight(),
	    			1, 0, mTabBar, false );
    	}
		mTabBar.startAnimation( tabBarAnimSet );
    }
    
    private AnimationSet createAnim( 
    		int aX1, int aX2, int aY1, int aY2,
    		float alpha1, float alpha2,
    		final UIWidget aWidget, final boolean aVisible ) {
    	AnimationSet animSet = new AnimationSet(false);
		TranslateAnimation transAnim = new TranslateAnimation( 
				aX1, aX2, aY1, aY2 );
		animSet.addAnimation( transAnim );
		AlphaAnimation alphaAnim = new AlphaAnimation( alpha1, alpha2 );
	    animSet.addAnimation( alphaAnim );
//		animSet.setFillAfter( true );
		animSet.setDuration( 400 );
		if ( aWidget != null ) {
			animSet.setAnimationListener( 
	    			new AnimationListener() {
	    				@Override
	    				public void onAnimationEnd(Animation animation) {
	    					aWidget.setVisibility( aVisible ? View.VISIBLE : View.GONE );
	    				}
	
	    				@Override
	    				public void onAnimationRepeat(Animation animation) {
	    				}
	
	    				@Override
	    				public void onAnimationStart(Animation animation) {
	    				}
	    			} );
		}
		return animSet;
    }

	private Handler mHandler = new Handler() {
		public void handleMessage( android.os.Message msg ) {
			switch ( msg.what ) {

			case MSG_RESIZE: 
				if ( msg.arg1 == RESIZE_ZOOM_OUT ) {
					if( isResizeViewShowTabBar() ) {
						mViewManager.setTabBarVisibility( true );
					}
				} else {
						mViewManager.setTabBarVisibility( false );
				}
				break;
			case MSG_SHOW_TABBAR:
				mViewManager.setTabBarVisibility( true );

				break;
			case MSG_HIDE_TABBAR:
				mViewManager.setTabBarVisibility( false );

				break;
			default:
				break;
			}
		};
	};

	private boolean isResizeViewShowTabBar() {
		Activity bv = mViewManager.getCurrentActivity();
		if (bv == null) {
			return true;
		}
		else {
			return (!((bv.getClass() == SearchView.class && ((SearchView)bv).getViewState() == SearchView.SEARCH_VIEW_RESULT) 
					||(bv.getClass() == DetailsView.class) 
					||(bv.getClass() == ForwardingView.class)
					||(bv.getClass() == WeiboAuthActivity.class)
					));
		}
	}
	
    /**
     * Initialization of all class fields
     */
    private void initFields() {
        mEventObserver = new EventObserver( this );
        
        mContainer = ( LinearLayout )findViewById( R.id.containerBody );
    	mMainView = (ResizeLayout) findViewById(R.id.resizeLayoutMain);
    	mMainView.setOnResizeListener(new ResizeLayout.OnResizeListener() {

			public void OnResize(int w, int h, int oldw, int oldh) {
    	
    		    if (((h > oldh) && ((h - oldh) > VIEW_RESIZE_LIMIT))
    			    || ((h < oldh) && ((oldh - h) > VIEW_RESIZE_LIMIT))) {
    			Message msg = new Message();
    			msg.what = MSG_RESIZE;

    			int change = RESIZE_ZOOM_OUT;
    			if (h < oldh) {
    			    change = RESIZE_ZOOM_IN;
    			}
    			msg.arg1 = change;
    			mHandler.sendMessage( msg );
    		    }
    		
    	    }
    	});
        mTabBar = ( TabBar )findViewById( R.id.mainTabBar );
        mTabBar.setListener( mEventObserver );
        mTabBar.setAnimEnabled( true );
        
        mTitleBar = ( TitleBar )findViewById( R.id.mainTitleBar );
        mTitleBar.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				( ( BaseActivity ) mViewManager.getCurrentActivity() ).clickToTop();
			}
		});
        mTxtView = (TextView)mTitleBar.findViewById(R.id.txtTitleBarTitle);
        mTxtView.setClickable(true);
        mTxtView.setOnClickListener(new OnClickListener() {
    	    @Override
    	    public void onClick(View v) {
    	    	( ( BaseActivity ) mViewManager.getCurrentActivity() ).clickToTop();

    	    }
    	});
        mSplash = ( Splash )findViewById( R.id.mainSplash );
        mSplash.setListener( mEventObserver );
        mSplash.setVisibility( View.VISIBLE );
        
        mUserGuide = ( ImageButton )findViewById( R.id.userGuide );
        mUserGuide.setVisibility( ImageButton.GONE );
        
        mViewManager = ViewManager.getInstance();
        mViewManager.setContainer( mContainer );
        
        // bundle data transferring doesn't support reference to object
        //   unless it is serializable or parcelable. So use viewmgr to pass eventobserver to next activity
        mViewManager.setMainActivity( this, mEventObserver );
    }
    
    @Override
    public boolean onPrepareOptionsMenu( Menu menu ) {
        LogUtils.d("in "+mViewManager.getCurrentActivity().getClass().toString());
        if(mViewManager.getCurrentActivity()!=null&&((Activity)(mViewManager.getCurrentActivity())!=MainActivity.this))
            return mViewManager.getCurrentActivity().onPrepareOptionsMenu( menu );
        return false;
    }
    
    @Override
    public boolean onOptionsItemSelected( MenuItem item ) {
        if (mViewManager.getCurrentActivity()!= null) {
            return mViewManager.getCurrentActivity().onOptionsItemSelected(item);
        }
        return false;
    }
    
    public void ShowTitleBarRefreshbutton(boolean isshow){
    		mTitleBar.showAssistButton(isshow);   
    		mTitleBar.showLoadingProgressBar( !isshow );
    }
    
    public void hideTitleBarRefreshbutton(boolean isshow){
		mTitleBar.showAssistButton(!isshow);   
	}
    public void showSubscriptionBtn(boolean isshow){
    	mTitleBar.showSubscriptionBtn(isshow);
    }
    
    public void showGraphicSelectBtn(boolean isshow){
    	mTitleBar.showGraphicSelectBtn(isshow);
    }
    
    public void showCategoryReadBtn(boolean isshow){
    	mTitleBar.showCategoryReadBtn(isshow);
    }
    
	public void setSubscriptionBtnOnClickerLister(OnClickListener aListener){
		mTitleBar.setSubscriptionBtnOnClickerLister(aListener);
	}
	
	public void setGraphicSelectBtnOnClickerLister(OnClickListener aListener){
		mTitleBar.setGraphicSelectBtnOnClickerLister(aListener);
	}
	
	public void setCategoryReadBtnOnClickerLister(OnClickListener aListener){
		mTitleBar.setCategoryReadBtnOnClickerLister(aListener);
	}
	
	public void ShowAssistButton(boolean isshow ){
		mTitleBar.showAssistButton(isshow);   
	}
	
	public void ShowLoadingProgressBar( boolean isshow ){
		mTitleBar.showLoadingProgressBar(isshow);
	}
	
	public void showNextButton( boolean isshow ){
		mTitleBar.showNextButton(isshow);
	}
	
	public void showPreButton( boolean isshow ){
		mTitleBar.showPreButton(isshow);
	}


	public void refreshWeatherBoxCity() {
		mTitleBar.refreshWeatherBoxCity();
	}
	
	/**
     * 城市选择
     * @param resultNum
     */
    public void citySelect(int resultNum,ILocalNewsChanged localNewsChanged) {
    	mTitleBar.citySelect(resultNum,localNewsChanged);
    }
    
	public void setUserGuideImage(int resid) {
		mUserGuide.setBackgroundResource(resid);
	}
	
	public void setUserGuideVisibility(int visibility) {
		mUserGuide.setVisibility(visibility);
	}
	public boolean isDispUserGuide() {
		return true;
	}
	public void setUserGuideOnClickListener(OnClickListener listener) {
	  mUserGuide.setOnClickListener(listener);
	}
	
	public class NotificationClickedReceiver extends BroadcastReceiver {

        @Override
        public void onReceive( Context context, Intent intent ) {
            LogUtils.d( "in" );
            mViewManager.showView(DownloadActivity.Id,
                    DownloadActivity.class, true, null);

        }
    }
	
	private void registerReceiver(){
        mReceiver = new NotificationClickedReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction( DownloadMgr.BROADCAST_ACTION );
        this.registerReceiver( mReceiver, filter );
    }
    
    private void unregisterReceiver(){
        if(mReceiver!=null)
            this.unregisterReceiver( mReceiver );
    }

}